package com.xlh.controller.user;

import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.xlh.common.Result;
import com.xlh.common.ResultEnum;
import com.xlh.constant.UserConstant;
import com.xlh.dto.PageDTO;
import com.xlh.dto.course.SkillDTO;
import com.xlh.dto.user.ClassInfoDTO;
import com.xlh.dto.user.UserClassDTO;
import com.xlh.dto.user.UserInfoDTO;
import com.xlh.enums.course.UserCourseStatusEnum;
import com.xlh.enums.user.ClassStatusEnum;
import com.xlh.enums.user.IdentityEnum;
import com.xlh.enums.user.RoleEnum;
import com.xlh.exception.common.NotFoundException;
import com.xlh.param.course.ClassCourseParam;
import com.xlh.param.user.CreateUserParam;
import com.xlh.param.user.UpdateClassParam;
import com.xlh.pojo.course.SkillNotes;
import com.xlh.pojo.user.Class;
import com.xlh.security.UserInfoHolder;
import com.xlh.service.course.CourseService;
import com.xlh.service.user.ClassService;
import com.xlh.service.user.UserService;
import com.xlh.util.ExcelsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 班级
 * <p>
 * Created by lx on 2019/1/25.
 */
@Api(tags = "ClassController", description = "班级")
@RestController
@RequestMapping("/course")
public class ClassController {

    @Autowired
    private ClassService classService;

    @Autowired
    private UserService userService;

    @Autowired
    private UserInfoHolder userInfoHolder;

    @Autowired
    private CourseService courseService;

    @ApiOperation("获取历史班级")
    @GetMapping("/history")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<UserClassDTO>> queryHistoryClass(
            @RequestParam(required = false) @ApiParam(value = "班级信息") String classInfo) {
        return Result.success(classService.queryHistoryClass(classInfo, userInfoHolder.getUserId()));
    }

    @ApiOperation("获取自然班级")
    @GetMapping("/natural-class")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<UserClassDTO>> queryNaturalClass(
            @RequestParam(required = false) @ApiParam(value = "班级信息") String classInfo) {
        return Result.success(classService.queryHistoryClass(classInfo, null));
    }

    @ApiOperation("获取历史班级入口")
    @GetMapping("/natural-class_and_history")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<Map<String, Object>>> queryNaturalAndHistoryClass(
            @RequestParam(required = false) @ApiParam(value = "班级信息") String classInfo,
            @RequestParam(required = false) @ApiParam(value = "课程id") Long courseid) {
        List<Map<String, Object>> list = new ArrayList<>();
        Long userid = userInfoHolder.getUserId();
        List<UserInfoDTO> courseTeachers = courseService.getCourseTeachers(courseid, null);
        if (courseTeachers.size() > 0 && courseTeachers.contains(userInfoHolder.getUserId())) {
            userid = courseTeachers.get(0).getId();
        }
        List<UserClassDTO> userClassDTOSh = classService.queryHistoryClass(classInfo, userid, "1");
        List<UserClassDTO> userClassDTOSn = classService.queryHistoryClass(classInfo, null, "1");
        HashMap<String, Object> map1 = new HashMap<String, Object>();
        HashMap<String, Object> map2 = new HashMap<String, Object>();
        HashMap<String, Object> map3 = new HashMap<String, Object>();
        JSONArray json = new JSONArray();
        JSONArray json1 = new JSONArray();
        JSONArray jso2 = new JSONArray();
        JSONArray json3 = new JSONArray();
        for (UserClassDTO userClassDTO : userClassDTOSh) {
            HashMap<String, Object> map4 = new HashMap<String, Object>();
            map4.put("label", userClassDTO.getName());
            map4.put("value", userClassDTO.getId());
            map4.put("selectAll", userClassDTO.getUsers());
            map4.put("grade", userClassDTO.getGrade());
            map4.put("userNumber", userClassDTO.getUsers().size());
            json.add(map4);
        }
        for (UserClassDTO userClassDTO : userClassDTOSn) {
            HashMap<String, Object> map5 = new HashMap<String, Object>();
            map5.put("label", userClassDTO.getName());
            map5.put("value", userClassDTO.getId());
            map5.put("selectAll", userClassDTO.getUsers());
            map5.put("grade", userClassDTO.getGrade());
            map5.put("userNumber", userClassDTO.getUsers().size());
            json1.add(map5);
        }
        map1.put("label", "系统班级");
        map1.put("value", 1);
        map1.put("children", json1);
        map2.put("label", "我的班级");
        map2.put("value", 2);
        map2.put("children", json);
        list.add(map1);
        list.add(map2);
        return Result.success(list);
    }

    @ApiOperation("获取班级列表分页")
    @GetMapping("/{courseId}/class/page")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<PageDTO<ClassInfoDTO>> queryHistoryClass(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "页数") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页显示条数") Integer pageSize,
            @RequestParam @ApiParam(value = "年级", required = true) String grade,
            @RequestParam @ApiParam(value = "结课状态", required = true) String classStatus) {
        ClassStatusEnum statusEnum = ClassStatusEnum.getByMessage(classStatus);
        return Result.success(classService.listClassByPage(pageNum, pageSize,
                courseId, statusEnum == null ? null : statusEnum.isCode(), grade));
    }

    @ApiOperation("添加班级")
    @PostMapping("/{courseId}/class")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<Long> createClass(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @RequestParam(required = false) @ApiParam(value = "导入文档") MultipartFile file,
            @RequestParam(required = false) @ApiParam(value = "导入学生的班级id") Long studentclassId,
            @RequestParam(required = false) @ApiParam(value = "姓名") String name,
            @RequestParam(required = false) @ApiParam(value = "年级") Integer grade,
            @RequestParam("studentIds") @ApiParam(value = "选择学生id集合", required = true) List<Long> studentIds,
            @RequestParam(required = false)
            @ApiParam(value = "用户对错误提示作出的决定 true：继续导入 false：过滤 null：没有作出决定") Boolean errorFlag) {

        // 解析excel文件
        List<CreateUserParam> excelParams = file == null ? Lists.newArrayList() : ExcelsUtil.readExcelData(
                file, UserConstant.STUDENT_COMMON_HEADER, 2, 3, CreateUserParam.class);
        // 创建班级，返回课程id
        return Result.success(
                classService.createClass(courseId, excelParams, studentclassId, name, grade, errorFlag,
                        queryuserId(courseId), studentIds));
    }

    @ApiOperation("添加班级")
    @PostMapping("/{courseId}/exist-class")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<Long> createClass(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @RequestParam(required = false) @ApiParam(value = "导入学生的班级id") Long studentclassId,
            @RequestParam(required = false)
            @ApiParam(value = "用户对错误提示作出的决定 true：继续导入 false：过滤 null：没有作出决定") Boolean errorFlag) {

        // 创建班级，返回课程id
        return Result.success(
                classService.createClass(courseId, studentclassId, errorFlag, queryuserId(courseId)));
    }

    private Long queryuserId(Long courseId) {
        Long userId = userInfoHolder.getUserId();
        List<UserInfoDTO> courseTeachers = courseService.getCourseTeachers(courseId, null);
        UserCourseStatusEnum userCourseStatusEnum = courseService.queryUserCourseStatus(courseId);
        if (CollectionUtils.isNotEmpty(courseTeachers)) {
            if (userInfoHolder.getUserId().equals(courseTeachers.get(0).getId())) {
                userId = userInfoHolder.getUserId();
            } else {
                if (!"NOT_CREATE_CLASS".equals(userCourseStatusEnum.name())) {
                    userId = courseTeachers.get(0).getId();
                }
            }
        }
        return userId;
    }

    @ApiOperation("修改班级")
    @PutMapping("/{courseId}/class/{classId}")
    @PreAuthorize("@permissionValidator.isTeaching(#courseId, #classId, false)")
    public Result updateClass(@PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
                              @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
                              @RequestBody @ApiParam(value = "修改班级参数") @Valid UpdateClassParam updateParam) {
        classService.updateClass(courseId, classId, updateParam);
        return Result.success();
    }

    @ApiOperation("批量删除班级")
    @PostMapping("/{courseId}/class/batch-delete")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result deleteBatchClass(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @RequestParam @ApiParam(value = "错误提示 true：继续删除 null：没有作出决定") Boolean errorFlag,
            @RequestBody @ApiParam(value = "需要删除的班级id") List<Long> classIds) {
        // 网络管理员删除：数据库真删，超管删除：数据库假删
        boolean logicDeleted = RoleEnum.INTERNET_ADMIN.getRoleCode() == userInfoHolder.getUser().getRole() ?
                false : true;

        classService.deleteBatchClass(courseId, classIds, errorFlag, logicDeleted);
        return Result.success();
    }

    @ApiOperation("结课")
    @PutMapping("/{courseId}/class/{classId}/end-class")
    @PreAuthorize("@permissionValidator.isTeaching(#courseId, #classId, false)")
    public Result endClass(@PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
                           @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
                           @RequestParam @ApiParam(value = "错误提示 true：继续结课 null：没有作出决定") Boolean errorFlag) {
        classService.endClass(courseId, classId, errorFlag);
        return Result.success();
    }

    @ApiOperation("获取学生列表分页")
    @GetMapping("/class/{classId}/student/page")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<PageDTO<UserInfoDTO>> listStudentByPage(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "页数") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页显示条数") Integer pageSize,
            @RequestParam(required = false) @ApiParam(value = "学生信息") String userInfo) {
        return Result.success(classService.listStudentByPage(pageNum, pageSize, classId, userInfo));
    }

    @ApiOperation("班级标识")
    @GetMapping("/class/{classId}/flag")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> queryClassInfoFlag(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId) {
        return Result.success(classService.queryClassInfoFlag(classId));
    }

    @ApiOperation("获取学生列表")
    @GetMapping("/{courseId}/class/{classId}/student")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<UserInfoDTO>> listStudent(@PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
                                                 @PathVariable("classId") @ApiParam(value = "班级id") Long classId) {
        return Result.success(userService.queryClassUser(Lists.newArrayList(classId), null));
    }

    @ApiOperation("获取导入学生列表")
    @PostMapping("/class/import_student")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<UserInfoDTO>> listImportStudent(@RequestBody @ApiParam(value = "选择学生id集合") List<Integer> studentIds,
                                                       @RequestParam(required = false) @ApiParam(value = "班级id") Long classId) {
        List<UserInfoDTO> userInfoDTOS = userService.queryClassUser(Lists.newArrayList(classId), null, studentIds);
        return Result.success(userInfoDTOS);
    }

    @ApiOperation("从Excel导入学生")
    @PostMapping("/{courseId}/class/{classId}/student/model-import")
    @PreAuthorize("@permissionValidator.isTeaching(#courseId, #classId, false)")
    public Result importStudentExcel(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam(value = "errorFlag")
            @ApiParam(value = "对错误信息作出的判断 true：导入 false：过滤 null：无判断", required = true) Boolean errorFlag,
            @RequestParam(value = "file") @ApiParam(value = "导入文档", required = true) MultipartFile file) {

        // 解析excel文件
        List<CreateUserParam> excelParams = ExcelsUtil.readExcelData(
                file, UserConstant.STUDENT_COMMON_HEADER, 2, 3, CreateUserParam.class);
        if (CollectionUtils.isEmpty(excelParams)) {
            return Result.error(ResultEnum.SERVER_ERROR, "excel暂无添加数据，请重新上传");
        }

        // 创建用户
        List<Long> userIds;
        try {
            userIds = userService.createUser(excelParams, IdentityEnum.STUDENT,
                    Lists.newArrayList(courseId), classId, errorFlag);
        } catch (NotFoundException e) {
            return Result.error(ResultEnum.SERVER_ERROR, "excel暂无添加数据，请重新上传");
        }

        // 创建班级和学生的关联关系
        classService.createUserClass(classId, userIds);
        return Result.success();

    }

    @ApiOperation("从Excel导入学生")
    @PostMapping("/Naclass/{classId}/student/model-import")
    @PreAuthorize("@permissionValidator.admin")
    public Result importNaStudentExcel(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam(value = "errorFlag")
            @ApiParam(value = "对错误信息作出的判断 true：导入 false：过滤 null：无判断", required = true) Boolean errorFlag,
            @RequestParam(value = "file") @ApiParam(value = "导入文档", required = true) MultipartFile file) {

        // 解析excel文件
        List<CreateUserParam> excelParams = ExcelsUtil.readExcelData(
                file, UserConstant.STUDENT_COMMON_HEADER, 2, 3, CreateUserParam.class);
        if (CollectionUtils.isEmpty(excelParams)) {
            return Result.error(ResultEnum.SERVER_ERROR, "excel暂无添加数据，请重新上传");
        }

        // 创建用户
        List<Long> userIds;
        try {
            userIds = userService.createUser(excelParams, IdentityEnum.STUDENT,
                    null, classId, errorFlag);
        } catch (NotFoundException e) {
            return Result.error(ResultEnum.SERVER_ERROR, "excel暂无添加数据，请重新上传");
        }

        // 创建班级和学生的关联关系
        classService.createUserClass(classId, userIds);
        return Result.success();
    }

    @ApiOperation("从Excel导入技能岗位")
    @PostMapping("/skill/model-import")
//    @PreAuthorize("@permissionValidator.teacher")
    public Result importSkillExcel(
            @RequestParam(value = "file") @ApiParam(value = "导入文档", required = true) MultipartFile file,
            @RequestParam(value = "skillId", required = false) Integer skillId,
            @RequestParam(value = "role", required = false) Integer role) {

        // 解析excel文件
        List<SkillDTO> allByExcel = ExcelsUtil.getAllByExcel(
                file, 0, 1);
        if (CollectionUtils.isEmpty(allByExcel)) {
            return Result.error(ResultEnum.SERVER_ERROR, "excel暂无添加数据，请重新上传");
        }
        //入库
        return Result.success(courseService.insertSkill(allByExcel, skillId, file, role));
    }

    @ApiOperation("查询技能岗位")
    @GetMapping(value = "/querySkillInfo")
//    @PreAuthorize("@permissionValidator.teacher")
    public Result queryClassInfo(@RequestParam(value = "skillId", required = false) Integer skillId) {
        List<SkillNotes> list = courseService.querySkill(skillId);
        return Result.success(list);
    }

    @ApiOperation("查询关联课程")
    @GetMapping(value = "/querySkillInfoCourse")
    public Result querySkillInfoCourse() {
        List<SkillNotes> list = courseService.querySkillCourse();
        return Result.success(list);
    }

    @ApiOperation("查询关联课程")
    @GetMapping(value = "/querySkillOther")
    public Result querySkillOther(@RequestParam(value = "skillId", required = false) Integer skillId) {
        Map<String, List<SkillNotes>> list = courseService.querySkillOther(skillId);
        return Result.success(list);
    }

    @ApiOperation("保存修改技能岗位")
    @PostMapping(value = "/saveOrUpdateSkill")
    public Result saveOrUpdateSkill(@RequestBody @ApiParam(value = "技能集合") List<SkillNotes> skillinfo) {
        courseService.saveOrUpdateSkill(skillinfo);
        return Result.success();
    }

    @ApiOperation("修改技能岗位")
    @GetMapping(value = "/updateSkillInfo")
    public Result updateSkillInfo(@RequestParam(value = "skillId", required = false) Integer skillId,
                                  @RequestParam(value = "name", required = false) String name) {
        courseService.updateSkill(skillId, name);
        return Result.success();
    }

    @ApiOperation("添加技能岗位")
    @PostMapping(value = "/insertSkillInfo")
    @PreAuthorize("@permissionValidator.admin")
    public Result insertSkillInfo(@RequestParam(value = "iconValue", required = false) String iconValue,
                                  @RequestParam(value = "name", required = false) String name) {
        courseService.insertOther(iconValue, name);
        return Result.success();
    }

    @ApiOperation("删除技能岗位")
    @DeleteMapping(value = "/deleteSkillInfo")
    @PreAuthorize("@permissionValidator.admin")
    public Result deleteSkillInfo(@RequestParam(value = "skillId", required = false) Integer skillId) {
        courseService.deleteSkill(skillId);
        return Result.success();
    }

    @ApiOperation("添加学生")
    @PostMapping("/{courseId}/class/{classId}/student")
    @PreAuthorize("@permissionValidator.isTeaching(#courseId, #classId, false)")
    public Result createStudent(@PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
                                @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
                                @RequestParam(value = "errorFlag")
                                @ApiParam(value = "对错误信息作出的判断 true：导入 false：过滤 null：无判断")
                                        Boolean errorFlag,
                                @RequestBody
                                @ApiParam(value = "创建用户参数", required = true)
                                @Valid CreateUserParam param) {
        List<Long> userIds = userService.createUser(Lists.newArrayList(param), IdentityEnum.STUDENT,
                Lists.newArrayList(courseId), classId, errorFlag);
        if (CollectionUtils.isEmpty(userIds)) {
            return Result.error(ResultEnum.NOT_FOUND, "暂无添加的学生");
        }
        classService.createUserClass(classId, userIds);
        return Result.success();
    }

    @ApiOperation("批量删除学生")
    @PostMapping("/{courseId}/class/{classId}/student/batch-delete")
    @PreAuthorize("@permissionValidator.isTeacher() and @permissionValidator.isTeaching(#courseId, #classId, false)")
    public Result deleteBatchStudent(
            @PathVariable("courseId") @ApiParam(value = "课程id") Long courseId,
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam @ApiParam(value = "错误提示 true：继续删除 null：没有作出决定") Boolean errorFlag,
            @RequestBody @ApiParam(value = "需要删除的学生id集合") List<Long> studentIds) {

        // 网络管理员删除：数据库真删，超管删除：数据库假删
        boolean logicDeleted = RoleEnum.INTERNET_ADMIN.getRoleCode() == userInfoHolder.getUser().getRole() ?
                false : true;

        // 删除用户
        userService.batchDeleteUser(courseId, classId, studentIds, logicDeleted, errorFlag, null);

        // 删除用户和班级的关联
        userService.batchDeleteUserClass(Lists.newArrayList(classId), studentIds, logicDeleted);
        return Result.success();
    }

    @ApiOperation("查询自然班級")
    @GetMapping(value = "/queryClassInfo")
    @PreAuthorize("@permissionValidator.admin")
    public Result queryClassInfo(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize,
                                 @RequestParam(value = "grade", required = false) String grade,
                                 @RequestParam(value = "classInfo", required = false) String classInfo) {

        PageDTO<ClassInfoDTO> classDTOPageDTO = classService.queryClassInfo(pageNum, pageSize, grade, classInfo);

        return Result.success(classDTOPageDTO);
    }

    @ApiOperation("查询自然班级年级")
    @GetMapping(value = "/queryNaturalClassInfo")
    @PreAuthorize("@permissionValidator.admin")
    public Result queryNaturalClassInfo() {
        List<String> classDTOPageDTO = classService.queryNaturalClassInfo();
        return Result.success(classDTOPageDTO);
    }

    @ApiOperation("添加自然班級")
    @PostMapping(value = "/saveClassInfo")
    @PreAuthorize("@permissionValidator.admin")
    public Result saveClassInfo(@RequestBody @ApiParam(value = "获取的参数", required = true) @Valid ClassCourseParam params) {
        classService.saveClassInfo(params);
        return Result.success();
    }

    @ApiOperation("修改自然班级")
    @PutMapping("/natural_class/{classId}")
    @PreAuthorize("@permissionValidator.admin")
    public Result updateNaturalClass(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestBody @ApiParam(value = "修改班级参数") @Valid UpdateClassParam updateParam) {
        classService.updateNaturalClass(null, classId, updateParam);
        return Result.success();
    }

    @ApiOperation("批量删除自然班级")
    @PostMapping("/natural_class/batch-delete")
    @PreAuthorize("@permissionValidator.admin")
    public Result deleteNaturalBatchClass(
            @RequestParam @ApiParam(value = "错误提示 true：继续删除 null：没有作出决定") Boolean errorFlag,
            @RequestBody @ApiParam(value = "需要删除的班级id") List<Long> classIds) {
        // 网络管理员删除：数据库真删，超管删除：数据库假删
        boolean logicDeleted = RoleEnum.INTERNET_ADMIN.getRoleCode() == userInfoHolder.getUser().getRole() ?
                false : true;

        classService.deleteNaturalBatchClass(classIds, errorFlag, logicDeleted);
        return Result.success();
    }

    @ApiOperation("批量删除自然班级学生")
    @PostMapping("/class/{classId}/student/batch-natural-delete")
    @PreAuthorize("@permissionValidator.admin")
    public Result deleteNaturalBatchStudent(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam @ApiParam(value = "错误提示 true：继续删除 null：没有作出决定") Boolean errorFlag,
            @RequestBody @ApiParam(value = "需要删除的学生id集合") List<Long> studentIds) {

        // 网络管理员删除：数据库真删，超管删除：数据库假删
        boolean logicDeleted = RoleEnum.INTERNET_ADMIN.getRoleCode() == userInfoHolder.getUser().getRole() ?
                false : true;

        // 删除用户
        userService.batchNaDeleteUser(null, classId, studentIds, logicDeleted, true);

        // 删除用户和班级的关联
        userService.batchDeleteUserClass(Lists.newArrayList(classId), studentIds, logicDeleted);
        return Result.success();
    }

    @ApiOperation("添加自然班级学生")
    @PostMapping("/class/{classId}/natural_student")
    @PreAuthorize("@permissionValidator.admin")
    public Result createNaturalStudent(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam(value = "errorFlag")
            @ApiParam(value = "对错误信息作出的判断 true：导入 false：过滤 null：无判断")
                    Boolean errorFlag,
            @RequestBody
            @ApiParam(value = "创建用户参数", required = true)
            @Valid CreateUserParam param) {
        List<Long> userIds = userService.createUser(Lists.newArrayList(param), IdentityEnum.STUDENT,
                null, classId, errorFlag);
        if (CollectionUtils.isEmpty(userIds)) {
            return Result.error(ResultEnum.NOT_FOUND, "暂无添加的学生");
        }
        classService.createUserClass(classId, userIds);
        return Result.success();
    }

    @ApiOperation("获取自然班级学生列表分页")
    @GetMapping("/class/{classId}/Natural_student/page")
    @PreAuthorize("@permissionValidator.admin")
    public Result<PageDTO<UserInfoDTO>> listNaturalStudentByPage(
            @PathVariable("classId") @ApiParam(value = "班级id") Long classId,
            @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "页数") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页显示条数") Integer pageSize,
            @RequestParam(required = false) @ApiParam(value = "学生信息") String userInfo) {
        return Result.success(classService.listStudentByPage(pageNum, pageSize, classId, userInfo));
    }

    @ApiOperation("获取班级基本信息")
    @GetMapping("/class/{classId}")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<Class> getClass(@PathVariable("classId") @ApiParam(value = "班级id") Long classId) {
        return Result.success(classService.queryClass(classId));
    }
}
